package com.ikas.ai.framework.node.impl;

import com.alibaba.fastjson.JSONObject;
import com.ikas.ai.framework.core.model.BatchDataFunction;
import com.ikas.ai.framework.core.model.NodeInputVariables;
import com.ikas.ai.framework.core.model.PageBatchOutput;
import com.ikas.ai.framework.core.model.PageQueryInput;
import com.ikas.ai.framework.flow.ScoreFlow;
import com.ikas.ai.framework.node.NodeType;

import java.util.function.Function;

/**
 * @Description: 批量数据处理
 * @Author: qi.yilai
 * @Date: 2023/10/27 10:33
 * @Version: 1.0.0
 **/
public class BatchDataNode extends AbstractNode<BatchDataFunction> {
    private Function<PageQueryInput, PageBatchOutput> function;
    private int queryType;
    private JSONObject queryConfig;
    private JSONObject meteData;

    public BatchDataNode(ScoreFlow scoreFlow, Function<PageQueryInput, PageBatchOutput> function, int queryType, JSONObject queryConfig, JSONObject meteData, Long nodeId, Long nodeInstanceId, String name) {
        super(scoreFlow, nodeId, nodeInstanceId, name);
        this.function = function;
        this.queryType = queryType;
        this.queryConfig = queryConfig;
        this.meteData = meteData;
    }

    @Override
    public synchronized void input(NodeInputVariables nodeInputVariables) {
        throw new UnsupportedOperationException("批量数据节点不支持输入操作");
    }

    @Override
    public NodeType type() {
        return NodeType.BATCH_DATA;
    }

    @Override
    BatchDataFunction doExecute() {
        BatchDataFunction batchDataFunction = new BatchDataFunction();
        batchDataFunction.setFunction(this.function);
        batchDataFunction.setQueryType(queryType);
        batchDataFunction.setQueryConfig(queryConfig);
        batchDataFunction.setMeteData(meteData);
        return batchDataFunction;
    }
}
